Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positives for non-standard variables in function-calc-no-unspaced-operator #6053

Merged
merged 1 commit into from May 1, 2022

Conversation

ybiquitous
Copy link
Member

Which issue, if any, is this issue related to?

Closes #6052

Is there anything in the PR that needs further explanation?

This pull request aims to fix false positives for non-standard variables (e.g. SCSS, Less, and so on.) in the function-calc-no-unspaced-operator rule.

I think isStandardSyntaxValue() is more appropriate than isStandardSyntaxMathFunction() suggested on #6052 (comment) because isStandardSyntaxMathFunction() fails the cases using non-standard variables. E.g.

{
code: 'a { top: calc(100%- #{$foo}); }',
fixed: 'a { top: calc(100% - #{$foo}); }',
message: messages.expectedBefore('-'),
line: 1,
column: 19,
endLine: 1,
endColumn: 20,
},

@@ -166,6 +167,8 @@ const rule = (primary, _secondaryOptions, context) => {

if (firstNode.type !== 'word') return false;

if (!isStandardSyntaxValue(firstNode.value)) return false;

const operatorIndex = firstNode.value.search(OPERATOR_REGEX);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] If the isStandardSyntaxValue() check is not performed, firstNode.value like #{$foo-bar} matches /[+-]/ (OPERATOR_REGEX):

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ybiquitous ybiquitous merged commit b4139dd into main May 1, 2022
@ybiquitous ybiquitous deleted the issue-6052 branch May 1, 2022 08:02
@ybiquitous
Copy link
Member Author

Changelog entry added:

  • Fixed: function-calc-no-unspaced-operator false positives for non-standard variables (#6053).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix false positives for SCSS variables in function-calc-no-unspaced-operator
2 participants